﻿using PdfSharpCore.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace PdfChartHelper.Models
{
    public class PieModel
    {
        /// <summary>
        /// 笔刷颜色池
        /// </summary>
        public static List<XBrush> colorpool = new List<XBrush>()
        {
            XBrushes.AliceBlue,
            XBrushes.AntiqueWhite,
            XBrushes.Aqua,
            XBrushes.Aquamarine,
            XBrushes.Azure,
            XBrushes.Beige,
            XBrushes.Blue,
            XBrushes.BlueViolet,
            XBrushes.CadetBlue,
            XBrushes.BurlyWood,
            XBrushes.Chartreuse,
            XBrushes.Coral,
            XBrushes.Crimson,
            XBrushes.Cyan,
            XBrushes.DimGray,
            XBrushes.Firebrick,
            XBrushes.Gainsboro,
            XBrushes.Gold,
            XBrushes.GreenYellow,
            XBrushes.HotPink,
            XBrushes.Indigo,
            XBrushes.Lavender,
            XBrushes.LawnGreen,
            XBrushes.Maroon,
            XBrushes.MediumPurple,
            XBrushes.Green,
            XBrushes.HotPink,
            XBrushes.Khaki,
            XBrushes.Magenta,
            XBrushes.MediumOrchid,
            XBrushes.NavajoWhite
        };

        /// <summary>
        /// 描述信息
        /// </summary>
        public string DESC { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        public double Num { get; set; }

        /// <summary>
        /// 边线颜色
        /// </summary>
        public XColor color { get; set; }

        /// <summary>
        /// 填充颜色
        /// </summary>
        public XBrush b_color { get; set; }

        /// <summary>
        /// 所占角度
        /// </summary>
        public double single { get; set; }

        public PieModel()
        {
            this.color = getRandomColor();
            this.b_color = getRandomBrush();
        }
        //随机获取Xcolors里面的衍射
        public XColor getRandomColor()
        {
            Type xcolor_type = typeof(XColors);

            List<PropertyInfo> pro_list = xcolor_type.GetProperties().ToList();

            Random ran = new Random(10086);

            PropertyInfo propertyInfo = pro_list.ElementAt(ran.Next(0, pro_list.Count));

            object res = Activator.CreateInstance(propertyInfo.PropertyType);

            return (XColor)res;
        }

        public XBrush getRandomBrush()
        {
            /*Type colors = typeof(XBrushes);

            List<PropertyInfo> pros = colors.GetProperties().ToList();

            Random ran = new Random(10086);
            

            PropertyInfo color = pros.ElementAt(ran.Next(0, pros.Count));

            object res = Activator.CreateInstance(color.PropertyType);

            XSolidBrush sb = (XSolidBrush)res;

            return sb;*/

            Random ran = new Random();

            return colorpool.ElementAt(ran.Next(0, colorpool.Count));
        }


    }
}
